package com.util;
import android.content.Context;
import android.database.DatabaseErrorHandler;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class DBHelper extends SQLiteOpenHelper {
    //***数据库名称
    private static  final String DATABASE_NAME = "info.db";
    //数据库版本号
    private static final int DATABASE_VERSION=1;
    //创建表,用户信息表
    public static final  String TABLE_USERINFO="user";
    //创建用户信息表，建表语句

    private static final String CREATE_USERINFO_SQL="CREATE TABLE "
            + TABLE_USERINFO
            + "(phone text primary key,"
            + "name text not null,"
            + "address text not null,"
            + "password text not null)";
    public DBHelper(Context context)
    {
        this(context,DATABASE_NAME,null,DATABASE_VERSION);

    }

    public DBHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
    }

    public DBHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version, DatabaseErrorHandler errorHandler) {
        super(context, name, factory, version, errorHandler);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(CREATE_USERINFO_SQL);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        if(newVersion > oldVersion)
        {
            db.execSQL("DROP TABLE IF EXISTS "+ TABLE_USERINFO);
            onCreate(db);

        }
    }
}